package com.gopay.remote.cps.approval;

import java.util.Date;

import com.gopay.common.constants.approval.ApprovalID;
import com.gopay.common.constants.approval.DecRequest;
import com.gopay.common.constants.approval.DecUserType;
import com.gopay.common.constants.approval.TargetValue;
import com.gopay.common.constants.dts.DtsQueryStatus;
import com.gopay.common.domain.approval.Approval;
import com.gopay.common.exception.ApprovalException;

/**
 * 分布式事务一致性框架接口实现
 * 
 * @author MA HUAN
 * 
 */
public interface CompDecisionRemoteService {
	/**
	 * 获取审批流程明细(如果有多个审批流程时可能会出现对应不一致情况)
	 * 
	 * <pre>
	 * 推荐使用:getApproval(TargetValue targetValue, int approvalId, String targetId);
	 * </pre>
	 * 
	 * @param target
	 *            任务目标
	 * @param targetId
	 *            任务目标编号
	 * @return
	 * @deprecated
	 */
	public Approval getApproval(TargetValue targetValue, String targetId);

	/**
	 * 获取审批流程明细
	 * 
	 * @param target
	 *            任务目标
	 * @param apprId
	 *            审批流程编号
	 * @param targetId
	 *            任务目标编号
	 * @return
	 */
	public Approval getApproval(TargetValue targetValue, ApprovalID apprId, String targetId);

	/**
	 * 查看用户是否有审批权限
	 * 
	 * @param targetValue
	 *            任务目标
	 * @param targetId
	 *            任务目标编号
	 * @param userId
	 *            用户ID
	 * @param userType
	 *            用户类型
	 * @return
	 */
	public boolean isDecision(TargetValue targetValue, String targetId, String userId, DecUserType userType);

	/**
	 * 流程审批
	 * 
	 * @param req
	 *            流程审批参数
	 * @return
	 * @throws ApprovalException
	 */
	public boolean doDecision(String tokenId, DecRequest req) throws ApprovalException;
	
	public boolean compensateDecision(String tokenId) throws Exception;
	
	public boolean isDecisionDone(String tokenId, DtsQueryStatus status, Date doTime);

	/**
	 * 审批流程回滚到上一节点
	 * 
	 * @param taskId
	 * @return
	 */
	public boolean doRollback(String tokenId, int taskId) throws ApprovalException;

	public boolean compensateRollback(String tokenId) throws Exception;
	
	public boolean isRollbackDone(String tokenId, DtsQueryStatus status);
}
